package com.lzx.iteam.net;

import android.os.Message;
import android.util.Log;
import com.lzx.iteam.bean.GroupManageCreate;
import com.lzx.iteam.bean.PayToolsGroupData;
import com.lzx.iteam.util.Constants;
import com.lzx.iteam.util.StringUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import static android.R.id.list;

public class GetTeamPermissionMsg extends CcMsgStructure {

    private static String TAG = "GetTeamPermissionMsg";
    Message mCallBack;

    public GetTeamPermissionMsg(Message callBack) {
        // Auto-generated constructor stub
        mCallBack = callBack;
    }

    @Override
    public void onReceive(JSONObject data) {
        Log.d(TAG, "OnRecive --->" + data.toString());
        if (mCallBack != null) {
            PayToolsGroupData datas= new PayToolsGroupData();
            try {
                JSONObject jsonObject = data.getJSONObject(AsynHttpClient.KEY_CC_DATA);
                JSONObject item=jsonObject.getJSONObject("info");
                datas.setApproval_admin_limit(item.getInt("approval_admin_limit"));
                datas.setAttendance_count_limit(item.getInt("attendance_count_limit"));
                datas.setMember_limit(item.getInt("member_limit"));
                datas.setAttendance_member_limit(item.getInt("attendance_member_limit"));
                datas.setCrm_member_limit(item.getInt("crm_member_limit"));
                datas.setWeekly_templ_limit(item.getInt("weekly_templ_limit"));
                datas.setWeekly_member_limit(item.getInt("weekly_member_limit"));
                datas.setCrm_status(item.getInt("crm_status"));
                datas.setLegwork_status(item.getInt("legwork_status"));
            } catch (JSONException e) {
                e.printStackTrace();
            }
            if (mCallBack != null) {
                mCallBack.arg1 = 0;
                mCallBack.obj = datas;
                mCallBack.sendToTarget();
            }

        }
    }

    @Override
    public void onError(int error, Object ret) {
        Log.d(TAG, "OnErrorCode ---> " + error);
        String errorMsg = null;
        if (ret != null) {
            JSONObject jData = null;
            try {
                jData = new JSONObject(ret.toString());
                errorMsg = jData.getString("msg");
            } catch (JSONException e) {
                errorMsg = "服务端数据解析失败!";
                e.printStackTrace();
            }
        }
        if (mCallBack != null) {
            mCallBack.arg1 = error;
            if (!StringUtil.isEmpty(errorMsg)) {
                mCallBack.obj = errorMsg;
            } else {
                mCallBack.obj = Constants.NETWORK_WRROR;
            }
            mCallBack.sendToTarget();
        }
    }

}
